package com.demo.service.impl;

import com.demo.bean.User;
import com.demo.dao.IUserDao;
import com.demo.dao.impl.UserDaoImpl;
import com.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

public class UserServiceImpl implements IUserService {

	@Autowired
	private IUserDao dao = new UserDaoImpl();

	@Override
	public boolean register(User user) {
		if (dao.queryByName(user.getUsername()) == null && dao.add(user)) {
			return true;
		}
		return false;
	}

	@Override
	public boolean login(User user) {
		User dUser = dao.queryByName(user.getUsername());
		if (dUser != null && dUser.getPassword().equals(user.getPassword())) {
			return true;
		}
		return false;
	}
}
